//
//  ProfileViewModel.swift
//  WeChatClient
//
//  Created by AI Assistant on 2025/10/31.
//

import Foundation
import Combine

class ProfileViewModel: ObservableObject {
    @Published var currentUser: User = User.currentUser
    @Published var showEditProfile: Bool = false
    @Published var showSettings: Bool = false
    @Published var showQRCode: Bool = false
    @Published var showPayment: Bool = false
    @Published var showFavorites: Bool = false
    @Published var showPhotos: Bool = false
    @Published var showCards: Bool = false
    @Published var showEmoji: Bool = false
    
    struct ProfileMenuItem: Identifiable {
        let id = UUID()
        let title: String
        let icon: String
        let action: ProfileMenuAction
    }
    
    enum ProfileMenuAction {
        case pay
        case collect
        case photos
        case cards
        case emoji
        case settings
    }
    
    var menuItems: [[ProfileMenuItem]] {
        return [
            [
                ProfileMenuItem(title: "支付", icon: "creditcard.fill", action: .pay),
                ProfileMenuItem(title: "收藏", icon: "star.fill", action: .collect)
            ],
            [
                ProfileMenuItem(title: "相册", icon: "photo.fill", action: .photos),
                ProfileMenuItem(title: "卡包", icon: "wallet.pass.fill", action: .cards),
                ProfileMenuItem(title: "表情", icon: "face.smiling.fill", action: .emoji)
            ],
            [
                ProfileMenuItem(title: "设置", icon: "gearshape.fill", action: .settings)
            ]
        ]
    }
    
    func handleMenuAction(_ action: ProfileMenuAction) {
        switch action {
        case .pay:
            showPayment = true
        case .collect:
            showFavorites = true
        case .photos:
            showPhotos = true
        case .cards:
            showCards = true
        case .emoji:
            showEmoji = true
        case .settings:
            showSettings = true
        }
    }
    
    func updateProfile(displayName: String, signature: String) {
        // 在实际应用中，这里会调用API更新用户信息
        // 这里只是更新本地状态
        currentUser = User(
            userName: currentUser.userName,
            displayName: displayName,
            avatar: currentUser.avatar,
            signature: signature,
            phoneNumber: currentUser.phoneNumber,
            isOnline: currentUser.isOnline
        )
        showEditProfile = false
    }
}
